import { observable, action } from 'mobx';
import * as API_SUBDEPARTMENT from '../apis/docofsubdepartment';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

export class DocOfSubDepartmentStore {
  @observable title = getLabel(33280, '分部文档数量');
  @observable loading = false;
  @observable conditions = [];
  @observable secNum = [];
  @observable docNum = [];
  @observable mostCategory = [];
  @observable reportData = [];
  @observable loadingChart = true;
  @observable loadingSN = true;
  @observable loadingDN = true;
  @observable loadingMC = true;
  constructor() {
    this.setTitle = this.setTitle.bind(this);
    this.setLoading = this.setLoading.bind(this);
    this.getCondition = this.getCondition.bind(this);
    this.getSecNum = this.getSecNum.bind(this);
    this.getDocNum = this.getDocNum.bind(this);
    this.getMostCategory = this.getMostCategory.bind(this);
    this.getReportData = this.getReportData.bind(this);
  }

  @action
  setTitle(title) {
    this.title = title;
  }

  setLoading(loading) {
    this.loading = loading;
  }

  getCondition(params = {}) {
    API_SUBDEPARTMENT.getCondition(params).then((data) => {
      this.conditions = data.conditions;
      this.conditions.forEach((item) => {
        item.labelcol = 3;
        item.fieldcol = 21;
      });
      this.conditions[0].options.forEach((item) => {
        if (item.key === '6') {
          this.conditions[0].selectLinkageDatas = {
            6: {
              conditionType: 'RANGEPICKER',
              domkey: ['doccreatedatefrom', 'doccreatedateto'],
            },
          };
        }
      });
    });
  }

  getSecNum(params = {}) {
    this.loadingSN = true;
    API_SUBDEPARTMENT.getSecNum(params).then((data) => {
      this.secNum = data;
      this.loadingSN = false;
    });
  }

  getDocNum(params = {}) {
    this.loadingDN = true;
    API_SUBDEPARTMENT.getDocNum(params).then((data) => {
      this.docNum = data;
      this.loadingDN = false;
    });
  }

  getMostCategory(params = {}) {
    this.loadingMC = true;
    API_SUBDEPARTMENT.getMostCategory(params).then((data) => {
      this.mostCategory = data;
      this.loadingMC = false;
    });
  }


  getReportData(params = {}) {
    this.loadingChart = true;
    API_SUBDEPARTMENT.getReportData(params).then((data) => {
      this.reportData = data;
      this.loadingChart = false;
    });
  }
}

